<?php

/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
App::uses('AppController', 'Controller');

/**
 * FieldOptions Controller
 *
 * @property FieldOption $FieldOption
 */
class FieldOptionsController extends AppController
{

    public $name = 'FieldOptions';

    /**
     * delete method
     *
     * @throws MethodNotAllowedException
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function admin_delete($id = null)
    {/*
      if (!$this->request->is('post'))
      {
      throw new MethodNotAllowedException();
      } */
        $this->FieldOption->id = $id;
        if (!$this->FieldOption->exists())
        {
            throw new NotFoundException(__('Invalid field option'));
        }
        if ($this->FieldOption->delete())
        {
            $this->Session->setFlash(__('Field option deleted'), Flash::Success);
            $this->redirect($this->referer());
        }
        $this->Session->setFlash(__('Field option was not deleted'), Flash::Error);
        $this->redirect($this->referer());
    }

    /**
     * Moves the passed field one position up
     * @param string $id Id of the phase
     */
    public function admin_moveup($id = null)
    {
        $this->FieldOption->moveHigher($id);
        $this->redirect($this->referer());
    }

    /**
     * Moves the passed field one position down
     * @param string $id Id of the phase
     */
    public function admin_movedown($id = null)
    {
        $this->FieldOption->moveLower($id);
        $this->redirect($this->referer());
    }

}
